package inno.specificMutaion;

import java.util.ArrayList;
import java.util.HashMap;

import inno.data.StockFullData;
import inno.specificOperator.Addition;
import inno.specificOperator.And;
import inno.specificOperator.BiggerThan;
import inno.specificOperator.MovingAvgOperator;
import inno.specificOperator.Multiply;
import inno.specificOperator.Or;
import inno.specificOperator.Power;
import inno.specificOperator.Subtraction;
import inno.specificOperator.Xor;
import inno.specificValue.ClosingPrice;
import inno.specificValue.HighPrice;
import inno.specificValue.LowPrice;
import inno.specificValue.OpenPrice;
import inno.specificValue.SimpleConst;
import inno.specificValue.SimpleConstBump;
import inno.treeRepro.Chromosome;
import inno.treeRepro.Node;

public class DummyMutation implements Mutation{
	private String stockFigure; // change this to get from a singelton

	private String operators [] = // all the options to choose from
		{
			"Addition","And","BiggerThan","MovingAvgOperator","Multiply","Operator","Or","Subtraction","Xor"
			
		};
	private String values [] = {"ClosingPrice","HighPrice","LowPrice","OpenPrice","SimpleConst"};
	public void doMutation(Chromosome subject){
		HashMap<Integer, ArrayList<Node>> treeMap = subject.getDfsMap();
		stockFigure= subject.getStockFigure();
		int randLevel = (int) Math.round(Math.random()*(treeMap.size()-1)); // choose the place where we want to do the mutation
		ArrayList<Node> tempNodeArray = treeMap.get(randLevel); // get the random node
		int randNode = (int) Math.round(Math.random()*(tempNodeArray.size()-1)); // choose the place where we want to do the mutation
		Node replacedNode = tempNodeArray.get(randNode);
		if (replacedNode.isSingleNoded())
		{
			if (replacedNode.getValueOperator().isConst()) // if it is a const number put a different const number
			{
				double chooseConst = Math.random();
				if (chooseConst>0.4){
					replacedNode.setValueOperator(new SimpleConst(Math.random()*100));
				}
				else{
					replacedNode.setValueOperator(new SimpleConstBump());
				}
			}
			else{
				int randValue = (int) Math.round(Math.random()*4); // choose a random value
				switch (randValue) { // get the random node
				        case 0:  replacedNode.setValueOperator(new ClosingPrice(stockFigure));
		          break;
				        case 1:  replacedNode.setValueOperator(new HighPrice(stockFigure)); 
		          break;
				        case 2: replacedNode.setValueOperator(new LowPrice(stockFigure)); 
		          break;
				        case 3:  replacedNode.setValueOperator(new OpenPrice(stockFigure)); 
		          break;
			
		          }
			}
		}
		else{
			int randOpt = (int) Math.round(Math.random()*4); // choose one of the opt
			Node tempNode =null;
	        switch (randOpt) {
		        case 0:  tempNode = new Node(null, new Addition()); 
                break;
		        case 1:  tempNode = new Node(null, new MovingAvgOperator(stockFigure)); 
                break;
		        case 2:  tempNode = new Node(null, new Multiply()); 
                break;
		        case 3:  tempNode = new Node(null, new Subtraction()); 
                break;
		        case 4:  tempNode = new Node(null, new Power()); 
                break;
               }
			
		}
		
		

	}

}
